import React, {
    Component,
} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Platform,
    Dimensions,
    TouchableOpacity,
    Image,
    Alert,
    FlatList,
    TextInput,
    Linking,
    ScrollView,
    Switch,
    DeviceEventEmitter,
    KeyboardAvoidingView
} from 'react-native';
import moment from 'moment';
import Loading from "../../../utils/Loading";
import HttpUtils from '../../../utils/HttpUtils';
import HttpUrls from '../../../utils/HttpUrls';
import Header from "../../../components/header";
import AndroidModule from '../../../utils/AndroidConnent'
import Constant from '../../../utils/Constant'//全局变量
import PublishCarPic from './components/PublishCarPic'
import PublishCarRadio from './components/PublishCarRadio'
import PublishCarVcode from './components/PublishCarVcode'
import PublishCarArrow from './components/PublishCarArrow'
import PublishCarTextInput from './components/PublishCarTextInput'
import PublishCarDisplacement from './components/PublishCarDisplacement'
import PublishCarSwitch from './components/PublishCarSwitch'
import DatePickerPart from '../../../components/Tool/DatePickerPart'
import RegionPickerView from '../../../components/Tool/RegionPickerView';
import { ToastToUser } from '../../../utils/CustomToast';
import { conditionObjWithType } from '../../../utils/Conditions'
import {getPerm} from "../../../utils/ComFunction";
import {PermissionType} from "../../../utils/Enum";


let navigation

const isIos = Platform.OS == 'ios';

let maxCarConditionLength = 2000

export default class PublishCarPage extends Component {

    constructor(props) {
        super(props);
        let carId = this.props.route && this.props.route.params && this.props.route.params.carId ? this.props.route.params.carId : '' //'10344863'
        let purchaseCenterPerm = getPerm(PermissionType.Permission_EnablePurchaseCenter)
        let backPage = this.props.route && this.props.route.params && this.props.route.params.backPage ? this.props.route.params.backPage : 'CarStockListPage'
        this.state = {
            purchaseCenterPerm,
            backPage,
            carId: carId,
            showCityPicker: false,
            employees: [],
            showDatePicker: false,
            showDatePickerType: '',
            dateTypeMode: '',
            isFranchisee: false,
            isExternalCarEntryUser: Constant.userInfo.isExternalCarEntryUser || 0, // 是否是外部车辆录入用户

            //参数
            carPics: [], //车辆图片
            carType: 2, //1: 新车，2: 二手车
            vcode: '', //车架号（v码）
            brand: '', //品牌id
            series: '', //车系id
            species: '', //车型id
            carName: '', //品牌+车系+车型
            speciesName: '',//品牌，seriesName+speciesName
            mileage: '', //里程
            displacement: '',//排量
            turbo: 0, //是否涡轮增压 0:否,1:是
            registerDate: '', //上牌日期
            outerColor: '', //外观颜色
            reportPic: '', //维保报告图片
            reportPcUrl: '', //维保报告链接
            reportPdf: '', //维保报告pdf
            detectionReportPic: '', //检测报告图片
            detectionReportUrl: '', //检测报告链接
            detectionReportPdf: '', //检测报告pdf
            innerNo: '', //车辆内部编号
            storeStatus: '', //库存状态 1:在途,2:在厅,3:外借,4:外借,5:转场,6:已出库
            storeStatusText: '',
            keyNum: '', //钥匙数量
            transferTimes: '', //过户次数
            useNature: '', //使用性质
            useNatureText: '',
            plateNumber: '', //车牌号
            ownershipEntity: 2, //所有权属性：1公户 2私户，
            ecode: '', //发动机号
            productionDate: '', //出厂日期
            innerColor: '', //内饰颜色
            gearboxType: '', //变速箱
            gearboxTypeText: '',
            emissionStd: '', //排放标准
            emissionStdText: '',
            energyType: '', //燃油类型
            energyTypeText: '',
            carRank: '', //车型级别
            carRankText: '',
            bodyStyle: '', //车身结构
            bodyStyleText: '',
            merchantCity: '', //所在地 
            annualInspectionDate: '', //年检到期时间
            insuranceDate: '', //交强险到期时间
            features: '', //车辆配置
            carCondition: '', //车况描述
            faultDescribe: '', //瑕疵
            purchaseType: '', //收购性质
            purchaseTypeText: '',
            purchasePrice: '', //收购价
            purchaser: '', //收购员id
            purchaserName: '', //收购员姓名
            purchaseDate: '', //收购日期
            purchaseRemark: '', //收购备注
            customerType: 1, //客户类型：1直客 2合作商
            customerName: '', //车主姓名
            customerPhone: '', //手机号码
            customerPayee: '', //收款人
            customerBankAccount: '', //银行卡号
            customerBankName: '', //开户行
            customerIdCard: '', //身份证号
            customerOtherAccount: '', //其他账户
            customerAddress: '', //地址
            guidePrice: '', //新车指导价
            markedPrice: '', //一口价（展厅标价）
            wholesalePrice: '', //批发价
            listPrice: '', //挂牌价
            joinUnion: 0, //上架到严选车源
            joinQuotationCenter: 0, //上架到报价中心

            isExpand: false,

        }
    }

    componentDidMount() {
        this.foursQueryListener = DeviceEventEmitter.addListener('foursQuery', e => {
            if (e.page == 'PublishCarPage') {
                navigation.navigate('FoursQuery', { vcode: e.vcode })
            }
        });

        let today = moment().format("YYYY-MM-DD")
        this.setState({
            purchaser: Constant.userInfo.userId,
            purchaseDate: today,
        })

        if (Constant.userInfo.isFranchisee) {//加盟商
            this.setState({
                isFranchisee: true,
                storeStatus: 1,
                storeStatusText: '在途',
                purchaseType: 3,
                purchaseTypeText: '寄售',
            })
        } else {
            this.setState({
                isFranchisee: false,
                storeStatus: 2,
                storeStatusText: '在厅',
                purchaseType: 1,
                purchaseTypeText: '全款',
            })
        }

        if (this.state.carId) {
            this.getOwnCarDetails()
        } else {
            this.getUsers()
        }

        this.selectBrandResult = DeviceEventEmitter.addListener('selectBrandResult', (result) => {
            if (result && result.from == 'PublishCarPage') {
                this.formatBrand(result)
            }
        })

        this.uploadCheckReport = DeviceEventEmitter.addListener('uploadCheckReport', (result) => {
            console.log('uploadCheckReport', result)
            if (result) {
                this.setState({
                    detectionReportPic: result.detectionReportPic,
                    detectionReportUrl: result.detectionReportUrl,
                    detectionReportPdf: result.detectionReportPdf,
                })
            }
        })

        this.uploadMaintenceReport = DeviceEventEmitter.addListener('uploadMaintenceReport', (result) => {
            console.log('uploadMaintenceReport', result)
            if (result) {
                this.setState({
                    reportPic: result.reportPic,
                    reportPcUrl: result.reportPcUrl,
                    reportPdf: result.reportPdf,
                    vcode: result.vcode
                })
            }
        })

    }

    componentWillUnmount() {
        this.selectBrandResult.remove()
        this.uploadCheckReport.remove()
        this.uploadMaintenceReport.remove()
        if (this.foursQueryListener) {
            this.foursQueryListener.remove();
        }
    }

    getUsers() {
        let param = {
            merchantId: Constant.userInfo.merchantId,
            pageSize: 200
        }
        HttpUtils.getRequest(HttpUrls.getUsersByMerchantId, param)
            .then((result) => {
                let dataArray = result.data
                this.setState({
                    employees: dataArray,
                })
                dataArray.map((item) => {
                    if (item.userId == this.state.purchaser) {
                        this.setState({
                            purchaserName: item.fullname
                        })
                    }
                })
            })
            .catch((error) => {

            });
    }

    getOwnCarDetails() {
        let param = {
            carId: this.state.carId
        }
        if (this.Loading) {
            this.Loading.show();
        }
        HttpUtils.getRequest(HttpUrls.getOwnCarDetails, param)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                let data = result.data
                this.formatValue(data)
                this.getUsers()
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }

    getCarCategoryByVin() {

        if (this.state.vcode.length != 17 || this.state.vcode.indexOf(' ') != -1) {
            return
        }
        let param = {
            vin: this.state.vcode
        }
        HttpUtils.getRequest(HttpUrls.getCarCategoryByVin, param)
            .then((result) => {
                if (result.data) {
                    let brandName = ''
                    let seriesName = ''
                    let speciesName = ''
                    result.data.map((item) => {
                        if (item.level == 1) {
                            brandName = item.name
                            this.setState({
                                brand: item.id
                            })
                        } else if (item.level == 3) {
                            seriesName = item.name
                            this.setState({
                                series: item.id
                            })
                        } else if (item.level == 5) {
                            speciesName = item.name
                            this.setState({
                                species: item.id
                            })
                        }
                    })
                    if (brandName && seriesName && speciesName) {
                        this.setState({
                            carName: brandName + '#' + seriesName + '#' + speciesName,
                            speciesName: seriesName + '·' + speciesName
                        })
                    }
                    this.getCarProductionConfiguration()
                }
            })
            .catch((error) => {

            });
    }

    formatValue(data) {
        let color = data.color ? data.color : []
        let outerColor = ''
        let innerColor = ''
        if (color.length > 0) {
            let colorOj = color[0]
            outerColor = colorOj.outerColor ? colorOj.outerColor : ''
            innerColor = colorOj.innerColor ? colorOj.innerColor : ''
        }

        this.state.employees.map((item) => {
            if (item.userId == this.state.purchaser) {
                this.setState({
                    purchaserName: item.fullname
                })
            }
        })

        let registerDate = ''
        if (data.registerDate) {
            let registerDateArray = data.registerDate.split('-')
            if (registerDateArray.length >= 2) {
                registerDate = registerDateArray[0] + '-' + registerDateArray[1]
            }
        }

        let productionDate = ''
        if (data.productionDate) {
            let productionDateArray = data.productionDate.split('-')
            if (productionDateArray.length >= 2) {
                productionDate = productionDateArray[0] + '-' + productionDateArray[1]
            }
        }

        this.setState({
            carPics: data.carPics ? data.carPics : [],
            carType: data.carType ? data.carType : 2,
            vcode: data.vcode ? data.vcode : '',
            brand: data.brand ? data.brand : '',
            series: data.series ? data.series : '',
            species: data.species ? data.species : '',
            carName: data.carName ? data.carName : '',
            speciesName: data.seriesName && data.speciesName ? (data.seriesName + '·' + data.speciesName) : '',
            mileage: data.mileage ? (data.mileage / 10000).toFixed(2) + '' : '',
            displacement: data.displacement != undefined && data.displacement != 'NaN' ? data.displacement + '' : '',
            turbo: data.turbo ? data.turbo : 0,
            registerDate: registerDate,
            outerColor: outerColor,
            reportPic: data.maintenanceRecord && data.maintenanceRecord.reportPics ? data.maintenanceRecord.reportPics.join(',') : '',
            reportPcUrl: data.maintenanceRecord && data.maintenanceRecord.reportPcUrl ? data.maintenanceRecord.reportPcUrl : '',
            reportPdf: data.maintenanceRecord && data.maintenanceRecord.reportPdf ? data.maintenanceRecord.reportPdf : '',
            detectionReportPic: data.detectionReportPic ? data.detectionReportPic : '',
            detectionReportUrl: data.detectionReportUrl ? data.detectionReportUrl : '',
            detectionReportPdf: data.detectionReportPdf ? data.detectionReportPdf : '',
            innerNo: data.innerNo ? data.innerNo : '',
            storeStatus: data.storeStatus ? data.storeStatus : 2,
            storeStatusText: data.storeStatus ? conditionObjWithType('storeStatus')[data.storeStatus] : '在厅',
            keyNum: data.keyNum != undefined ? data.keyNum + '' : '',
            transferTimes: data.carType == 2 && data.transferTimes != undefined ? data.transferTimes + '' : '',
            useNature: data.useNature ? data.useNature + '' : '',
            useNatureText: data.useNature ? conditionObjWithType('useNature')[data.useNature] : '',
            plateNumber: data.plateNumber ? data.plateNumber : '',
            ownershipEntity: data.ownershipEntity ? data.ownershipEntity : 2,
            ecode: data.ecode ? data.ecode : '',
            productionDate: productionDate,
            innerColor: innerColor,
            gearboxType: data.gearboxType ? data.gearboxType : '',
            gearboxTypeText: data.gearboxType ? conditionObjWithType('gearboxType')[data.gearboxType] : '',
            emissionStd: data.emissionStd ? data.emissionStd : '',
            emissionStdText: data.emissionStd ? conditionObjWithType('emissionStd')[data.emissionStd] : '',
            energyType: data.energyType ? data.energyType : '',
            energyTypeText: data.energyType ? conditionObjWithType('energyType')[data.energyType] : '',
            carRank: data.carRank ? data.carRank : '',
            carRankText: data.carRank ? conditionObjWithType('carRank')[data.carRank] : '',
            bodyStyle: data.bodyStyle ? data.bodyStyle : '',
            bodyStyleText: data.bodyStyle ? conditionObjWithType('bodyStyle')[data.bodyStyle] : '',
            // merchantCity: data.merchantCity ? data.merchantCity : '',
            annualInspectionDate: data.annualInspectionDate ? data.annualInspectionDate : '',
            insuranceDate: data.insuranceDate ? data.insuranceDate : '',
            features: data.features ? data.features : '',
            carCondition: data.carCondition ? data.carCondition : '',
            faultDescribe: data.faultDescribe ? data.faultDescribe : '',
            purchaseType: data.purchaseType ? data.purchaseType : 1,
            purchaseTypeText: data.purchaseType ? conditionObjWithType('purchaseType')[data.purchaseType] : '全款',
            purchasePrice: data.purchasePrice && data.purchasePrice + '' != '' ? (data.purchasePrice / 10000).toFixed(2) + '' : '',
            purchaser: data.purchaser ? data.purchaser : Constant.userInfo.userId,
            purchaserName: data.purchaserName ? data.purchaserName : '',
            purchaseDate: data.purchaseDate ? data.purchaseDate : '',
            purchaseRemark: data.purchaseRemark ? data.purchaseRemark : '',

            customerType: data.carInfoExtend && data.carInfoExtend.customerType ? data.carInfoExtend.customerType : 1,
            customerName: data.carInfoExtend && data.carInfoExtend.customerName ? data.carInfoExtend.customerName : '',
            customerPhone: data.carInfoExtend && data.carInfoExtend.customerPhone ? data.carInfoExtend.customerPhone : '',
            customerPayee: data.carInfoExtend && data.carInfoExtend.customerPayee ? data.carInfoExtend.customerPayee : '',
            customerBankAccount: data.carInfoExtend && data.carInfoExtend.customerBankAccount ? data.carInfoExtend.customerBankAccount : '',
            customerBankName: data.carInfoExtend && data.carInfoExtend.customerBankName ? data.carInfoExtend.customerBankName : '',
            customerIdCard: data.carInfoExtend && data.carInfoExtend.customerIdCard ? data.carInfoExtend.customerIdCard : '',
            customerOtherAccount: data.carInfoExtend && data.carInfoExtend.customerOtherAccount ? data.carInfoExtend.customerOtherAccount : '',
            customerAddress: data.carInfoExtend && data.carInfoExtend.customerAddress ? data.carInfoExtend.customerAddress : '',

            guidePrice: data.guidePrice && data.guidePrice + '' != '' ? (data.guidePrice / 10000).toFixed(2) + '' : '',
            markedPrice: data.markedPrice != undefined ? (data.markedPrice / 10000).toFixed(2) + '' : '',
            wholesalePrice: data.wholesalePrice && data.wholesalePrice != undefined ? data.wholesalePrice / 10000 + '' : '',
            listPrice: data.listPrice && data.listPrice != undefined ? (data.listPrice / 10000).toFixed(2) + '' : '',
            joinUnion: data.joinUnion + '' != '1' ? 0 : 1,
            joinQuotationCenter: data.joinQuotationCenter + '' != '1' ? 0 : 1,

        })

    }

    getCarProductionConfiguration() {
        if (!this.state.species) {
            return
        }

        if (this.state.guidePrice && this.state.energyType && this.state.displacement && this.state.gearboxType && this.state.bodyStyle && this.state.emissionStd && this.state.carRank) {
            return;
        }

        let param = {
            species: this.state.species
        }
        HttpUtils.getRequest(HttpUrls.getCarConfigDetailBySpecies, param)
            .then((result) => {
                if (result.data) {
                    result.data.map((item) => {
                        let key = item.detailName
                        let value = item.detailValue
                        if (key.indexOf('厂商指导价') != -1 && !this.state.guidePrice) {
                            value = value.replace('万', '')
                            this.setState({
                                guidePrice: value
                            })
                        }
                        if (key.indexOf('能源类型') != -1 && !this.state.energyType) {
                            if (value == '汽油') {
                                this.setState({
                                    energyType: 1,
                                    energyTypeText: '汽油'
                                })
                            } else if (value == '柴油') {
                                this.setState({
                                    energyType: 2,
                                    energyTypeText: '柴油'
                                })
                            } else if (value == '油电混合') {
                                this.setState({
                                    energyType: 3,
                                    energyTypeText: '油电混合'
                                })
                            } else if (value == '纯电动') {
                                this.setState({
                                    energyType: 4,
                                    energyTypeText: '纯电动'
                                })
                            } else if (value == '氢燃料电池') {
                                this.setState({
                                    energyType: 5,
                                    energyTypeText: '氢燃料电池'
                                })
                            } else if (value == '插电式混合动力') {
                                this.setState({
                                    energyType: 6,
                                    energyTypeText: '插电式混合动力'
                                })
                            } else if (value == '增程式') {
                                this.setState({
                                    energyType: 7,
                                    energyTypeText: '增程式'
                                })
                            } else if (value == '增汽油+48V轻混系统程式') {
                                this.setState({
                                    energyType: 8,
                                    energyTypeText: '增汽油+48V轻混系统程式'
                                })
                            }
                        }
                        if (key.indexOf('排量') != -1 && !this.state.displacement && !isNaN(parseFloat(value))) {
                            value = parseFloat(value) / 1000
                            this.setState({ displacement: value + '' })
                        }
                        if (key.indexOf('进气形式') != -1 && !this.state.turbo) {
                            if (value.indexOf('自然吸气') != -1) {
                                this.setState({ turbo: 0 })
                            } else {
                                this.setState({ turbo: 1 })
                            }
                        }
                        if (key.indexOf('变速箱') != -1 && !this.state.gearboxType) {
                            if (value.indexOf('手动') != -1) {
                                this.setState({
                                    gearboxType: 1,
                                    gearboxTypeText: '手动'
                                })
                            } else if (value.indexOf('自动') != -1) {
                                this.setState({
                                    gearboxType: 2,
                                    gearboxTypeText: '自动'
                                })
                            } else if (value.indexOf('手自一体') != -1) {
                                this.setState({
                                    gearboxType: 3,
                                    gearboxTypeText: '手自一体'
                                })
                            } else if (value.indexOf('双离合') != -1) {
                                this.setState({
                                    gearboxType: 4,
                                    gearboxTypeText: '双离合'
                                })
                            } else if (value.indexOf('无级变速') != -1) {
                                this.setState({
                                    gearboxType: 5,
                                    gearboxTypeText: '无级变速'
                                })
                            } else if (value.indexOf('AMT') != -1) {
                                this.setState({
                                    gearboxType: 6,
                                    gearboxTypeText: 'AMT'
                                })
                            } else {
                                this.setState({
                                    gearboxType: 9,
                                    gearboxTypeText: '其它'
                                })
                            }
                        }
                        if (key.indexOf('车身结构') != -1 && !this.state.bodyStyle) {
                            if (value.indexOf('两厢') != -1) {
                                this.setState({
                                    bodyStyle: 1,
                                    bodyStyleText: '两厢'
                                })
                            } else if (value.indexOf('三厢') != -1) {
                                this.setState({
                                    bodyStyle: 2,
                                    bodyStyleText: '三厢'
                                })
                            } else if (value.indexOf('掀背') != -1) {
                                this.setState({
                                    bodyStyle: 3,
                                    bodyStyleText: '掀背'
                                })
                            } else if (value.indexOf('旅行版') != -1) {
                                this.setState({
                                    bodyStyle: 4,
                                    bodyStyleText: '旅行版'
                                })
                            } else if (value.indexOf('硬顶敞篷') != -1) {
                                this.setState({
                                    bodyStyle: 5,
                                    bodyStyleText: '硬顶敞篷'
                                })
                            } else if (value.indexOf('软顶敞篷') != -1) {
                                this.setState({
                                    bodyStyle: 6,
                                    bodyStyleText: '软顶敞篷'
                                })
                            } else if (value.indexOf('硬顶跑车') != -1) {
                                this.setState({
                                    bodyStyle: 7,
                                    bodyStyleText: '硬顶跑车'
                                })
                            } else if (value.indexOf('客车') != -1) {
                                this.setState({
                                    bodyStyle: 8,
                                    bodyStyleText: '客车'
                                })
                            } else if (value.indexOf('货车') != -1) {
                                this.setState({
                                    bodyStyle: 9,
                                    bodyStyleText: '货车'
                                })
                            }
                        }
                        if (key.indexOf('级别') != -1 && !this.state.carRank) {
                            if (value.indexOf('微型') != -1) {
                                this.setState({
                                    carRank: 'a00',
                                    carRankText: '微型'
                                })
                            } else if (value.indexOf('小型车') != -1) {
                                this.setState({
                                    carRank: 'a0',
                                    carRankText: '小型车'
                                })
                            } else if (value.indexOf('紧凑') != -1) {
                                this.setState({
                                    carRank: 'a',
                                    carRankText: '紧凑'
                                })
                            } else if (value.indexOf('中型车') != -1) {
                                this.setState({
                                    carRank: 'b',
                                    carRankText: '中型车'
                                })
                            } else if (value.indexOf('大型车') != -1) {
                                this.setState({
                                    carRank: 'd',
                                    carRankText: '大型车'
                                })
                            } else if (value.indexOf('SUV') != -1) {
                                this.setState({
                                    carRank: 'suv',
                                    carRankText: 'SUV'
                                })
                            } else if (value.indexOf('MPV') != -1) {
                                this.setState({
                                    carRank: 'mpv',
                                    carRankText: 'MPV'
                                })
                            } else if (value.indexOf('跑车') != -1) {
                                this.setState({
                                    carRank: 's',
                                    carRankText: '跑车'
                                })
                            } else if (value.indexOf('皮卡') != -1) {
                                this.setState({
                                    carRank: 'pk',
                                    carRankText: '皮卡'
                                })
                            }
                        }
                        if (key.indexOf('环保标准') != -1 && !this.state.emissionStd) {
                            if (value.indexOf('国I') != -1) {
                                this.setState({
                                    emissionStd: 1,
                                    emissionStdText: '国I'
                                })
                            } else if (value.indexOf('国II') != -1) {
                                this.setState({
                                    emissionStd: 2,
                                    emissionStdText: '国II'
                                })
                            } else if (value.indexOf('国III') != -1) {
                                this.setState({
                                    emissionStd: 3,
                                    emissionStdText: '国III'
                                })
                            } else if (value.indexOf('国IV') != -1) {
                                this.setState({
                                    emissionStd: 4,
                                    emissionStdText: '国IV'
                                })
                            } else if (value.indexOf('国V') != -1) {
                                this.setState({
                                    emissionStd: 5,
                                    emissionStdText: '国V'
                                })
                            } else if (value.indexOf('国VI') != -1) {
                                this.setState({
                                    emissionStd: 6,
                                    emissionStdText: '国VI'
                                })
                            }
                        }
                    })
                }
            })
            .catch((error) => {

            });
    }


    render() {
        navigation = this.props.navigation;
        let behavior = isIos ? '' : 'height';
        return (
            <KeyboardAvoidingView style={styles.container} behavior={behavior} >
                <Header navigation={navigation} Title={this.state.carId ? '编辑车辆' : '入库'} ></Header>

                <ScrollView style={{ flex: 1 }}>
                    {/* 图片资料 */}
                    <PublishCarPic
                        carPics={this.state.carPics}
                        picUrlChanged={(results) => {
                            this.setState({
                                carPics: results
                            })
                        }}
                    />

                    {/* 基本信息 */}
                    {this.renderBasicInfo()}
                    {/* 车辆档案 */}
                    {this.renderCarRecordShow()}
                    {this.renderCarRecord()}
                    {/* 车辆配置 */}
                    {this.renderCarConfiguration()}
                    {/* 车况描述 */}
                    {this.renderCarDescription()}
                    {/* 瑕疵描述 */}
                    {
                        !this.state.isFranchisee ?
                            this.renderCarDefect()
                            :
                            null
                    }

                    {/* 收购信息 */}
                    { this.state.isExternalCarEntryUser == 0 ? this.renderPurchaseInfo() : null}

                    {/* 车主信息 */}
                    {this.renderCarOwnerInfo()}
                    {/* 销售信息 */}
                    {this.renderSaleInfo()}

                    {/* 底部保存 */}
                    {this.renderBottomBox()}

                    <View style={{ height: Constant.bottomHeight }} />

                </ScrollView>

                <Loading onRef={(ref) => (this.Loading = ref)} />

                <DatePickerPart type={this.state.dateTypeMode} defaultDate={this.state[this.state.showDatePickerType]} show={this.state.showDatePicker} changeState={
                    (val) => { // 时间选择组件显示与否
                        this.setState({
                            showDatePicker: val,
                            dateTypeMode: '',
                        })
                    }
                } changeDate={(date) => {
                    this.setState({
                        [this.state.showDatePickerType]: date,
                        dateTypeMode: '',
                    })
                }} />

                <RegionPickerView
                    show={this.state.showCityPicker}
                    mode={'pc'}
                    hide={() => {
                        this.setState({
                            showCityPicker: false
                        })
                    }}
                    selectArea={(item) => {
                        this.setState({
                            showCityPicker: false,
                            merchantCity: item.cityName
                        })
                    }}
                />
            </KeyboardAvoidingView>
        );
    }

    renderBasicInfo() {
        return (
            <View style={styles.basicInfoContainer}>
                <Text style={styles.baseText}>基本信息</Text>
                <PublishCarRadio
                    name={'车辆类型'}
                    necessary={true}
                    radioValue={this.state.carType}
                    radioItems={[{ title: '二手车', value: 2 }, { title: '新车', value: 1 }]}
                    clickHandle={(value) => {
                        this.setState({
                            carType: value
                        })
                    }}
                />
                <PublishCarVcode
                    vcode={this.state.vcode}
                    vCodeChanged={(value) => {
                        this.setState({
                            vcode: value
                        }, function () {
                            this.getCarCategoryByVin()
                        })
                    }}
                />
                <PublishCarArrow
                    name={'品牌车型'}
                    necessary={true}
                    content={this.state.speciesName}
                    clickHandle={() => {
                        let params = { from: 'PublishCarPage' }
                        AndroidModule.selectBrand(params, (error, result) => {
                            this.formatBrand(result)
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'表显里程'}
                    necessary={this.state.carType == 2 ? true : false}
                    value={this.state.mileage}
                    unit={'万公里'}
                    keyboardType={'decimal-pad'}
                    onChangeText={(value) => {
                        this.setState({
                            mileage: value
                        })
                    }}
                />
                <PublishCarDisplacement
                    displacement={this.state.displacement}
                    turbo={this.state.turbo}
                    onChangeTurbo={(value) => {
                        this.setState({
                            turbo: value
                        })
                    }}
                    onChangeText={(value) => {
                        this.setState({
                            displacement: value
                        })
                    }}
                />
                <PublishCarArrow
                    name={'上牌日期'}
                    necessary={this.state.carType == 2 ? true : false}
                    content={this.state.registerDate}
                    clickHandle={() => {
                        this.setState({
                            showDatePickerType: 'registerDate',
                            showDatePicker: true
                        })
                    }}
                />
                <PublishCarArrow
                    name={'外观颜色'}
                    necessary={true}
                    content={this.state.outerColor}
                    clickHandle={() => {
                        navigation.navigate('CarColorPage', {
                            carColorType: '0',
                            selectedColor: this.state.outerColor,
                            completion: (color) => {
                                this.setState({
                                    outerColor: color
                                })
                            }
                        })
                    }}
                />

                {/** 
                 * 车辆档案指定显示字段：库存状态、过户次数、使用性质、所有权归属、年检到期、交强到期
                    增加必选项：变速箱、排放标准、燃油类型、车型级别、新车指导价
                */}

                <PublishCarArrow
                    name={'库存状态'}
                    content={this.state.storeStatusText}
                    clickHandle={() => {
                        navigation.navigate('RadioBoxPage', {
                            title: '请选择库存状态',
                            radioType: 'storeStatus',
                            selectedEnum: this.state.storeStatus,
                            completion: (type, des) => {
                                this.setState({
                                    storeStatus: type,
                                    storeStatusText: des
                                })
                            }
                        })
                    }}
                />

                {
                    this.state.carType == 2 ?
                        <PublishCarTextInput
                            name={'过户次数'}
                            value={this.state.transferTimes}
                            unit={'次'}
                            keyboardType={'number-pad'}
                            onChangeText={(value) => {
                                this.setState({
                                    transferTimes: value
                                })
                            }}
                        />
                        :
                        null
                }

                <PublishCarArrow
                    name={'使用性质'}
                    content={this.state.useNatureText}
                    clickHandle={() => {
                        navigation.navigate('RadioBoxPage', {
                            title: '请选择使用性质',
                            radioType: 'useNature',
                            selectedEnum: this.state.useNature,
                            completion: (type, des) => {
                                this.setState({
                                    useNature: type,
                                    useNatureText: des
                                })
                            }
                        })
                    }}
                />

                <PublishCarRadio
                    name={'所有权归属'}
                    radioValue={this.state.ownershipEntity}
                    radioItems={[{ title: '公户', value: 1 }, { title: '私户', value: 2 }]}
                    clickHandle={(value) => {
                        this.setState({
                            ownershipEntity: value
                        })
                    }}
                />

                <PublishCarArrow
                    name={'变速箱'}
                    content={this.state.gearboxTypeText}
                    clickHandle={() => {
                        navigation.navigate('RadioBoxPage', {
                            title: '请选择变速箱',
                            radioType: 'gearboxType',
                            selectedEnum: this.state.gearboxType,
                            completion: (type, des) => {
                                this.setState({
                                    gearboxType: type,
                                    gearboxTypeText: des
                                })
                            }
                        })
                    }}
                />
                <PublishCarArrow
                    name={'排放标准'}
                    content={this.state.emissionStdText}
                    necessary={true}
                    clickHandle={() => {
                        navigation.navigate('RadioBoxPage', {
                            title: '请选择排放标准',
                            radioType: 'emissionStd',
                            selectedEnum: this.state.emissionStd,
                            completion: (type, des) => {
                                this.setState({
                                    emissionStd: type,
                                    emissionStdText: des
                                })
                            }
                        })
                    }}
                />
                <PublishCarArrow
                    name={'燃油类型'}
                    content={this.state.energyTypeText}
                    necessary={true}
                    clickHandle={() => {
                        navigation.navigate('RadioBoxPage', {
                            title: '请选择燃油类型',
                            radioType: 'energyType',
                            selectedEnum: this.state.energyType,
                            completion: (type, des) => {
                                this.setState({
                                    energyType: type,
                                    energyTypeText: des
                                })
                            }
                        })
                    }}
                />

                <PublishCarArrow
                    name={'年检到期'}
                    content={this.state.annualInspectionDate}
                    clickHandle={() => {
                        this.setState({
                            dateTypeMode: 'YYYY-MM-DD',
                            showDatePickerType: 'annualInspectionDate',
                            showDatePicker: true
                        })
                    }}
                />
                <PublishCarArrow
                    hideSepline={true}
                    name={'交强险到期'}
                    content={this.state.insuranceDate}
                    clickHandle={() => {
                        this.setState({
                            dateTypeMode: 'YYYY-MM-DD',
                            showDatePickerType: 'insuranceDate',
                            showDatePicker: true
                        })
                    }}
                />

                <PublishCarArrow
                    name={'维保出险'}
                    placeholder={'请上传维保出险报告'}
                    content={this.state.reportPic || this.state.reportPcUrl || this.state.reportPdf ? '已上传' : ''}
                    clickHandle={() => {
                        let params = {
                            reportPic: this.state.reportPic,
                            reportPcUrl: this.state.reportPcUrl,
                            reportPdf: this.state.reportPdf,
                            vcode: this.state.vcode,
                            page: 'PublishCarPage'
                        }
                        AndroidModule.uploadMaintenanceReport(params, (error, result) => {
                            this.setState({
                                reportPic: result.reportPic,
                                reportPcUrl: result.reportPcUrl,
                                reportPdf: result.reportPdf,
                                vcode: result.vcode
                            })
                        })
                    }}
                />
                <PublishCarArrow
                    name={'车辆检测报告'}
                    placeholder={'请上传车辆检测报告'}
                    hideSepline={true}
                    content={this.state.detectionReportUrl || this.state.detectionReportPic || this.state.detectionReportPdf ? '已上传' : ''}
                    clickHandle={() => {
                        let params = {
                            detectionReportPic: this.state.detectionReportPic,
                            detectionReportUrl: this.state.detectionReportUrl,
                            detectionReportPdf: this.state.detectionReportPdf
                        }
                        AndroidModule.selectCarDetection(params, (error, result) => {
                            this.setState({
                                detectionReportPic: result.detectionReportPic,
                                detectionReportUrl: result.detectionReportUrl,
                                detectionReportPdf: result.detectionReportPdf
                            })
                        })
                    }}
                />
            </View>
        )
    }

    renderCarRecordShow() {
        return (
            <View style={[styles.basicInfoContainer, { paddingTop: 0 }]}>





            </View>
        )
    }

    renderCarRecord() {
        return (
            <View style={[styles.basicInfoContainer, { paddingTop: 0 }]}>
                <View style={{ width: '100%', flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', height: 40 }}>
                    <Text style={[styles.baseText, { marginBottom: 0 }]}>车辆档案{(this.state.isFranchisee ? <Text style={{ color: '#FB3D3C' }}>{' 信息越全，给价越快'}</Text> : null)}</Text>
                    <TouchableOpacity
                        style={styles.expandBox}
                        onPress={() => {
                            let isExpand = this.state.isExpand
                            this.setState({
                                isExpand: !isExpand
                            })
                        }}
                    >
                        <Text style={styles.expandText}>{this.state.isExpand ? '收起' : '展开'}</Text>
                        <Image style={styles.expandImg} source={this.state.isExpand ? require('source/image/up_icon.png') : require('source/image/down_icon.png')} />
                    </TouchableOpacity>
                </View>

                {/** 
                 * 车辆档案指定显示字段：库存状态、过户次数、使用性质、所有权归属、年检到期、交强到期
                    增加必选项：变速箱、排放标准、燃油类型、车型级别、新车指导价
                */}

                {
                    this.state.isExpand ?
                        <View>
                            <PublishCarTextInput
                                name={'车辆内部编号'}
                                value={this.state.innerNo}
                                onChangeText={(value) => {
                                    this.setState({
                                        innerNo: value
                                    })
                                }}
                            />
                            
                            <PublishCarTextInput
                                name={'钥匙数量'}
                                value={this.state.keyNum}
                                unit={'把'}
                                keyboardType={'number-pad'}
                                onChangeText={(value) => {
                                    this.setState({
                                        keyNum: value
                                    })
                                }}
                            />
                            
                            <PublishCarTextInput
                                name={'车牌号'}
                                value={this.state.plateNumber}
                                onChangeText={(value) => {
                                    this.setState({
                                        plateNumber: value
                                    })
                                }}
                            />
                           
                            <PublishCarTextInput
                                name={'发动机号'}
                                keyboardType={isIos ? 'ascii-capable' : 'default'}
                                value={this.state.ecode}
                                onChangeText={(value) => {
                                    this.setState({
                                        ecode: value
                                    })
                                }}
                            />
                            <PublishCarArrow
                                name={'出厂日期'}
                                content={this.state.productionDate}
                                clickHandle={() => {
                                    this.setState({
                                        showDatePickerType: 'productionDate',
                                        showDatePicker: true
                                    })
                                }}
                            />
                            <PublishCarArrow
                                name={'内饰颜色'}
                                content={this.state.innerColor}
                                clickHandle={() => {
                                    navigation.navigate('CarColorPage', {
                                        carColorType: '1',
                                        selectedColor: this.state.innerColor,
                                        completion: (color) => {
                                            this.setState({
                                                innerColor: color
                                            })
                                        }
                                    })
                                }}
                            />

                            <PublishCarArrow
                                name={'车型级别'}
                                content={this.state.carRankText}
                                clickHandle={() => {
                                    navigation.navigate('RadioBoxPage', {
                                        title: '请选择车型级别',
                                        radioType: 'carRank',
                                        selectedEnum: this.state.carRank,
                                        completion: (type, des) => {
                                            this.setState({
                                                carRank: type,
                                                carRankText: des
                                            })
                                        }
                                    })
                                }}
                            />
                            <PublishCarArrow
                                name={'车身结构'}
                                content={this.state.bodyStyleText}
                                clickHandle={() => {
                                    navigation.navigate('RadioBoxPage', {
                                        title: '请选择车身结构',
                                        radioType: 'bodyStyle',
                                        selectedEnum: this.state.bodyStyle,
                                        completion: (type, des) => {
                                            this.setState({
                                                bodyStyle: type,
                                                bodyStyleText: des
                                            })
                                        }
                                    })
                                }}
                            />
                            {/* <PublishCarArrow
                    name={'所在地'}
                    content={this.state.merchantCity}
                    clickHandle={() => {
                        this.selectCity()
                    }}
                /> */}
                            
                        </View>
                        :
                        null
                }
            </View>
        )
    }

    renderCarConfiguration() {
        return (
            <View style={styles.basicInfoContainer}>
                <Text style={styles.baseText}>车辆配置</Text>
                <PublishCarArrow
                    hideSepline={true}
                    name={'车辆配置'}
                    content={this.state.features ? '已配置' : ''}
                    clickHandle={() => {
                        navigation.navigate('CarConfigurationPage', {
                            preSelectedString: this.state.features,
                            editCompletion: (features) => {
                                this.setState({
                                    features
                                })

                                navigation.goBack()
                            }
                        })
                    }}
                />
            </View>
        )
    }

    renderCarDescription() {
        return (
            <View style={[styles.basicInfoContainer, { paddingVertical: 11 }]}>
                <Text style={styles.baseText1}>车况描述<Text style={{ color: '#FB3D3C' }}>*</Text></Text>
                <View style={styles.descBg}>
                    <TextInput
                        autoCorrect={false}
                        editable={true}
                        multiline={true}
                        maxLength={maxCarConditionLength}
                        autoCapitalize='characters'
                        style={styles.textInput}
                        placeholder={'请输入对外展示的车况描述'}
                        placeholderTextColor="#999999"
                        value={this.state.carCondition}
                        onChangeText={this.changeText.bind(this, 'carCondition')}
                    />
                    <Text style={styles.lengthText}>{this.state.carCondition.length + '/' + maxCarConditionLength}</Text>
                </View>
            </View>
        )
    }

    renderCarDefect() {
        return (
            <View style={[styles.basicInfoContainer, { paddingVertical: 11 }]}>
                <Text style={styles.baseText1}>瑕疵描述（仅本店员工可见）</Text>
                <View style={styles.descBg}>
                    <TextInput
                        autoCorrect={false}
                        editable={true}
                        multiline={true}
                        maxLength={maxCarConditionLength}
                        autoCapitalize='characters'
                        style={styles.textInput}
                        placeholder={'请输入车辆瑕疵详情'}
                        placeholderTextColor="#999999"
                        value={this.state.faultDescribe}
                        onChangeText={this.changeText.bind(this, 'faultDescribe')}
                    />
                    <Text style={styles.lengthText}>{this.state.faultDescribe.length + '/' + maxCarConditionLength}</Text>
                </View>
            </View>
        )
    }

    renderPurchaseInfo() {
        return (
            <View style={styles.basicInfoContainer}>
                <Text style={styles.baseText}>收购信息（仅本店员工可见）</Text>
                <PublishCarArrow
                    name={'收购性质'}
                    content={this.state.purchaseTypeText}
                    clickHandle={() => {
                        navigation.navigate('RadioBoxPage', {
                            title: '请选择收购性质',
                            radioType: 'purchaseType',
                            selectedEnum: this.state.purchaseType,
                            completion: (type, des) => {
                                this.setState({
                                    purchaseType: type,
                                    purchaseTypeText: des
                                })
                            }
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'收购价'}
                    value={this.state.purchasePrice}
                    keyboardType={'decimal-pad'}
                    unit={'万元'}
                    onChangeText={(value) => {
                        this.setState({
                            purchasePrice: value
                        })
                    }}
                />
                <PublishCarArrow
                    name={'收购员'}
                    content={this.state.purchaserName}
                    clickHandle={() => {
                        navigation.navigate('SellerSelectPage', {
                            selectedUserId: this.state.purchaser,
                            employees: this.state.employees,
                            selectCompletion: (item) => {
                                this.setState({
                                    purchaser: item.userId,
                                    purchaserName: item.fullname
                                })
                                navigation.goBack()
                            }
                        })
                    }}
                />
                <PublishCarArrow
                    name={'收购日期'}
                    content={this.state.purchaseDate}
                    clickHandle={() => {
                        this.setState({
                            dateTypeMode: 'YYYY-MM-DD',
                            showDatePickerType: 'purchaseDate',
                            showDatePicker: true
                        })
                    }}
                />
                <View style={[styles.basicInfoContainer, { paddingVertical: 11, marginTop: 0, paddingHorizontal: 0 }]}>
                    <Text style={styles.baseText1}>收购备注</Text>
                    <View style={styles.descBg}>
                        <TextInput
                            autoCorrect={false}
                            editable={true}
                            multiline={true}
                            maxLength={maxCarConditionLength}
                            autoCapitalize='characters'
                            style={styles.textInput}
                            placeholder={'请输入收购备注'}
                            placeholderTextColor="#999999"
                            value={this.state.purchaseRemark}
                            onChangeText={this.changeText.bind(this, 'purchaseRemark')}
                        />
                        <Text style={styles.lengthText}>{this.state.purchaseRemark.length + '/' + maxCarConditionLength}</Text>
                    </View>
                </View>
            </View>
        )
    }

    renderCarOwnerInfo() {
        return (
            <View style={styles.basicInfoContainer}>
                <Text style={styles.baseText}>车主信息（仅本店员工可见）</Text>
                <PublishCarRadio
                    name={'客户类型'}
                    radioValue={this.state.customerType}
                    radioItems={[{ title: '私人', value: 1 }, { title: '车商', value: 2 }]}
                    clickHandle={(value) => {
                        this.setState({
                            customerType: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'车主姓名'}
                    value={this.state.customerName}
                    onChangeText={(value) => {
                        this.setState({
                            customerName: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'手机号码'}
                    keyboardType={'phone-pad'}
                    hideSepline={true}
                    value={this.state.customerPhone}
                    onChangeText={(value) => {
                        this.setState({
                            customerPhone: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'身份证号'}
                    value={this.state.customerIdCard}
                    onChangeText={(value) => {
                        this.setState({
                            customerIdCard: value
                        })
                    }}
                />
                {/* <PublishCarTextInput
                    name={'收款人'}
                    value={this.state.customerPayee}
                    onChangeText={(value) => {
                        this.setState({
                            customerPayee: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'银行卡号'}
                    keyboardType={'number-pad'}
                    value={this.state.customerBankAccount}
                    onChangeText={(value) => {
                        this.setState({
                            customerBankAccount: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'开户行'}
                    value={this.state.customerBankName}
                    onChangeText={(value) => {
                        this.setState({
                            customerBankName: value
                        })
                    }}
                />
                
                <PublishCarTextInput
                    name={'其它账户'}
                    value={this.state.customerOtherAccount}
                    onChangeText={(value) => {
                        this.setState({
                            customerOtherAccount: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={'地址'}
                    hideSepline={true}
                    value={this.state.customerAddress}
                    onChangeText={(value) => {
                        this.setState({
                            customerAddress: value
                        })
                    }}
                /> */}
            </View>
        )
    }

    renderSaleInfo() {
        return (
            <View style={styles.basicInfoContainer}>
                <Text style={styles.baseText}>销售信息</Text>
                <PublishCarTextInput
                    name={'新车指导价'}
                    keyboardType={'decimal-pad'}
                    value={this.state.guidePrice}
                    unit={'万元'}
                    necessary={true}
                    onChangeText={(value) => {
                        this.setState({
                            guidePrice: value
                        })
                    }}
                />
                <PublishCarTextInput
                    name={this.state.isFranchisee ? '展厅价' : '一口价'}
                    keyboardType={'decimal-pad'}
                    placeholder={'请输入' + (this.state.isFranchisee ? '展厅价' : '一口价')}
                    value={this.state.markedPrice}
                    unit={'万元'}
                    onChangeText={(value) => {
                        if (value > 9000) {
                            ToastToUser('价格不能超过9千万')
                            this.setState({
                                markedPrice: ''
                            })
                        } else {
                            this.setState({
                                markedPrice: value
                            })
                        }

                    }}
                />
                {
                    this.state.isFranchisee ?
                        <PublishCarTextInput
                            name={'挂牌价'}
                            keyboardType={'decimal-pad'}
                            placeholder={'请输入挂牌价'}
                            value={this.state.listPrice}
                            unit={'万元'}
                            onChangeText={(value) => {

                                if (value > 9000) {
                                    ToastToUser('价格不能超过9千万')
                                    this.setState({
                                        listPrice: ''
                                    })
                                } else {
                                    this.setState({
                                        listPrice: value
                                    })
                                }

                            }}
                        />
                        :
                        <PublishCarTextInput
                            name={'批发价'}
                            keyboardType={'decimal-pad'}
                            value={this.state.wholesalePrice}
                            unit={'万元'}
                            onChangeText={(value) => {
                                this.setState({
                                    wholesalePrice: value
                                })
                            }}
                        />
                }

                {/* 服务中心才可以上传到报价中心 */}
                {
                    this.state.isFranchisee && (
                        <PublishCarSwitch
                            name={'上架到报价中心'}
                            value={this.state.joinQuotationCenter}
                            valueChanged={(value) => {
                                this.setState({
                                    joinQuotationCenter: value
                                })
                            }}
                        />
                    )
                }

                {/* 严选会员才可以上架到严选车源 */}
                {
                    Constant.userInfo.memberClass == '40' && (
                        <PublishCarSwitch
                            name={'上架到严选车源'}
                            value={this.state.joinUnion}
                            valueChanged={(value) => {
                                this.setState({
                                    joinUnion: value
                                })
                            }}
                        />
                    )
                }


            </View>
        )
    }

    renderBottomBox() {
        return (
            <View style={styles.bottomBox}>
                <TouchableOpacity
                    style={styles.saveBox}
                    onPress={() => {
                        this.save()
                    }}
                >
                    <Text style={styles.saveText}>保存</Text>
                </TouchableOpacity>
            </View>
        )
    }

    //输入框内容输入
    changeText(type, val) {
        this.setState({
            [type]: val
        })
    }

    selectCity() {
        this.setState({
            showCityPicker: true
        })
    }

    checkCarInfoInput() {
        
    }

    save() {
        let params = {
            isOnSales: 0,
            joinScBrand: Constant.userInfo.memberClass == 40 ? 1 : 0,
            merchantId: Constant.userInfo.merchantId,
        }

        // navigation.replace('CarPublishSuccessPage', {carId: 10470289, action: 'add'})
        // return;

        if (this.state.joinQuotationCenter == 1 || this.state.joinUnion == 1) {
            // this.checkCarInfoInput()

            if (this.state.carPics.length <= 0) {
                ToastToUser('请上传车辆图片')
                return 
            }
            if (!this.state.vcode) {
                ToastToUser('请填写VIN码')
                return
            }
            if (this.state.vcode.indexOf(' ') != -1) {
                ToastToUser('请输入正确的VIN码')
                return
            }
            if (this.state.vcode.length > 0 && this.state.vcode.length != 17) {
                ToastToUser('请输入正确的VIN码')
                return
            }
    
            //检测报告
            if ((this.state.detectionReportPic || this.state.detectionReportUrl || this.state.detectionReportPdf) && !this.state.vcode) {
                ToastToUser('请上传VIN码')
                return
            }
    
            if (!this.state.brand) {
                ToastToUser('请选择品牌车型')
                return
            }
            if (!this.state.mileage && this.state.carType == 2) {
                ToastToUser('请填写表显里程')
                return
            }
            if (!this.state.displacement) {
                ToastToUser('请填写排量')
                return
            }
            if (!this.state.registerDate && this.state.carType == 2) {
                ToastToUser('请选择上牌日期')
                return
            }
            if (!this.state.outerColor) {
                ToastToUser('请选择外观颜色')
                return
            }
            if (!this.state.carCondition) {
                ToastToUser('请填写车况描述')
                return
            }
            if (this.state.customerPhone && this.state.customerPhone.length != 11) {
                ToastToUser('请填写正确的手机号码')
                return
            }
            if (this.state.customerIdCard && this.state.customerIdCard.length != 18) {
                ToastToUser('请填写正确的身份证号码')
                return
            }
            if (!this.state.guidePrice) {
                ToastToUser('请输入新车指导价')
                return
            }
            if(!this.state.emissionStd){
                ToastToUser('请选择排放标准')
                return
            }
            if(!this.state.energyType){
                ToastToUser('请选择燃油类型')
                return
            }
        }

        //车辆图片
        if (this.state.carPics) {
            params['carPics'] = this.state.carPics
        }
        //车辆类型
        params['carType'] = this.state.carType
        //vin码
        if (this.state.vcode) {
            params['vcode'] = this.state.vcode
        }
        //品牌车型
        if (this.state.brand) {
            params['brand'] = this.state.brand
            params['series'] = this.state.series
            params['species'] = this.state.species
            params['speciesName'] = this.state.speciesName
            params['carName'] = this.state.carName
        }
        //里程
        if (this.state.mileage) {
            params['mileage'] = parseFloat(this.state.mileage) * 10000
        }

        //排量
        params['displacement'] = this.state.displacement
        params['turbo'] = this.state.turbo

        //上牌日期
        if (this.state.registerDate) {
            params['registerDate'] = this.state.registerDate
        }
        //外观颜色
        params['outerColor'] = this.state.outerColor
        //维保报告
        if (this.state.reportPic) {
            params['reportPic'] = this.state.reportPic
        }
        if (this.state.reportPcUrl) {
            params['reportPcUrl'] = this.state.reportPcUrl
        }
        if (this.state.reportPdf) {
            params['reportPdf'] = this.state.reportPdf
        }
        //检测报告
        if (this.state.detectionReportPic) {
            params['detectionReportPic'] = this.state.detectionReportPic
        }
        if (this.state.detectionReportUrl) {
            params['detectionReportUrl'] = this.state.detectionReportUrl
        }
        if (this.state.detectionReportPdf) {
            params['detectionReportPdf'] = this.state.detectionReportPdf
        }
        //车辆内部编号
        if (this.state.innerNo) {
            params['innerNo'] = this.state.innerNo
        }
        //库存状态
        if (this.state.storeStatus) {
            params['storeStatus'] = this.state.storeStatus
        }
        //钥匙数量
        if (this.state.keyNum.length > 0) {
            params['keyNum'] = this.state.keyNum
        }
        //过户次数
        if (this.state.carType == 2 && this.state.transferTimes.length > 0) {
            params['transferTimes'] = this.state.transferTimes
        }
        //使用性质
        if (this.state.useNature) {
            params['useNature'] = this.state.useNature
        }
        //车牌号
        if (this.state.plateNumber) {
            params['plateNumber'] = this.state.plateNumber
        }
        //所有权归属
        params['ownershipEntity'] = this.state.ownershipEntity
        //发动机号
        if (this.state.ecode) {
            params['ecode'] = this.state.ecode
        }
        //出厂日期
        if (this.state.productionDate) {
            params['productionDate'] = this.state.productionDate
        }
        //内饰颜色
        if (this.state.innerColor) {
            params['innerColor'] = this.state.innerColor
        }
        let colorObj = { 'outerColor': this.state.outerColor }
        if (this.state.innerColor) {
            colorObj['innerColor'] = this.state.innerColor
        }
        params['color'] = [colorObj]
        //变速箱
        if (this.state.gearboxType) {
            params['gearboxType'] = this.state.gearboxType
        }
        //排放标准
        if (this.state.emissionStd) {
            params['emissionStd'] = this.state.emissionStd
        }
        //燃油类型
        if (this.state.energyType) {
            params['energyType'] = this.state.energyType
        }
        //车型级别
        if (this.state.carRank) {
            params['carRank'] = this.state.carRank
        }
        //车身结构
        if (this.state.bodyStyle) {
            params['bodyStyle'] = this.state.bodyStyle
        }
        //所在地
        // if (this.state.merchantCity) {
        //     params['merchantCity'] = this.state.merchantCity
        // }
        //年检到期
        if (this.state.annualInspectionDate) {
            params['annualInspectionDate'] = this.state.annualInspectionDate
        }
        //交强险到期
        if (this.state.insuranceDate) {
            params['insuranceDate'] = this.state.insuranceDate
        }
        //车辆配置
        if (this.state.features) {
            params['features'] = this.state.features
        }
        //车况描述
        if (this.state.carCondition) {
            params['carCondition'] = this.state.carCondition
        }
        //瑕疵
        if (this.state.faultDescribe) {
            params['faultDescribe'] = this.state.faultDescribe
        }
        //收购性质
        if (this.state.purchaseType) {
            params['purchaseType'] = this.state.purchaseType
        }
        //收购价
        if (this.state.purchasePrice) {
            params['purchasePrice'] = Math.ceil(this.state.purchasePrice * 10000)
        }
        //收购员
        if (this.state.purchaser) {
            params['purchaser'] = this.state.purchaser
        }
        //收购日期
        if (this.state.purchaseDate) {
            params['purchaseDate'] = this.state.purchaseDate
        }
        //收购备注
        if (this.state.purchaseRemark) {
            params['purchaseRemark'] = this.state.purchaseRemark
        }

        let carInfoExtend = {}
        if (this.state.carId) {
            carInfoExtend['carId'] = this.state.carId
        }
        //客户类型
        carInfoExtend['customerType'] = this.state.customerType
        //车主姓名
        if (this.state.customerName) {
            carInfoExtend['customerName'] = this.state.customerName
        }
        //手机号码
        if (this.state.customerPhone) {
            carInfoExtend['customerPhone'] = this.state.customerPhone
        }
        //收款人
        if (this.state.customerPayee) {
            carInfoExtend['customerPayee'] = this.state.customerPayee
        }
        //银行卡号
        if (this.state.customerBankAccount) {
            carInfoExtend['customerBankAccount'] = this.state.customerBankAccount
        }
        //开户行
        if (this.state.customerBankName) {
            carInfoExtend['customerBankName'] = this.state.customerBankName
        }
        //身份证号
        if (this.state.customerIdCard) {
            carInfoExtend['customerIdCard'] = this.state.customerIdCard
        }
        //其他账户
        if (this.state.customerOtherAccount) {
            carInfoExtend['customerOtherAccount'] = this.state.customerOtherAccount
        }
        //地址
        if (this.state.customerAddress) {
            carInfoExtend['customerAddress'] = this.state.customerAddress
        }
        params['carInfoExtend'] = carInfoExtend

        //新车指导价
        if (this.state.guidePrice) {
            params['guidePrice'] = Math.ceil(this.state.guidePrice * 10000)
        }
        //一口价、展厅价
        if (this.state.markedPrice) {
            params['markedPrice'] = Math.ceil(this.state.markedPrice * 10000)
        }
        //批发价
        if (this.state.wholesalePrice) {
            params['wholesalePrice'] = Math.ceil(this.state.wholesalePrice * 10000)
        }
        //挂牌价
        if (this.state.listPrice) {
            params['listPrice'] = Math.ceil(this.state.listPrice * 10000)
        }

        if (this.state.isFranchisee) {
            //上架到报价中心
            params['joinQuotationCenter'] = this.state.joinQuotationCenter
        } else {
            //上架到严选车源
            params['joinUnion'] = this.state.joinUnion
        }

        params['operator'] = Constant.userInfo.fullname

        console.log('params = ', params)

        if (this.state.carId) {
            this.updateCar(params)
        } else {
            this.addCar(params)
        }
    }

    updateCar(params) {
        if (this.Loading) {
            this.Loading.show('车辆编辑中...');
        }
        params['carId'] = this.state.carId
        HttpUtils.postRequest(HttpUrls.updateCar, params)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                if (result.code == 0) {
                    ToastToUser('编辑成功!')
                    setTimeout(() => {
                        console.log('this.props.route.params', this.props.route.params)
                        if (this.props.route.params && this.props.route.params.completion) {
                            this.props.route.params.completion()
                        } else {
                            if(this.state.isExternalCarEntryUser == 1){
                                navigation.reset({
                                    index: 0,
                                    routes: [
                                        {
                                            name: 'MainTab',
                                            params: { initialRouteName: 'MyCarSourcePage' }
                                        }
                                    ],
                                });
                            }else {
                                if(this.state.purchaseCenterPerm){
                                    // 跳转至发布成功页面
                                    navigation.replace('CarPublishSuccessPage', {carId: this.state.carId, action: 'edit', backPage: this.state.backPage})
                                }else {
                                    navigation.replace('CarStockListPage');
                                }
                            }
                        }
                    }, 1000);
                } else {
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }

    addCar(params) {
        if (this.Loading) {
            this.Loading.show('车辆入库中...');
        }
        // console.log('backPage = ', this.state.backPage)
        // navigation.replace('CarPublishSuccessPage', {carId: '10470316', action: 'add', backPage: this.state.backPage})
        // return

        HttpUtils.postRequest(HttpUrls.addCar, params)
            .then((result) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
                if (result.code == 0) {
                    console.log('入库成功result = ', result.data.carId)
                    ToastToUser('入库成功!')
                    setTimeout(() => {
                        DeviceEventEmitter.emit('publishCarSuccess', {})
                        if (this.props.route.params && this.props.route.params.completion) {
                            this.props.route.params.completion()
                        } else {
                            if(this.state.isExternalCarEntryUser == 1){
                                navigation.reset({
                                    index: 0,
                                    routes: [
                                        {
                                            name: 'MainTab',
                                            params: { initialRouteName: 'MyCarSourcePage' }
                                        }
                                    ],
                                });
                            }else {
                                if(this.state.purchaseCenterPerm){
                                    // 跳转至发布成功页面
                                    navigation.replace('CarPublishSuccessPage', {carId: result.data.carId, action: 'add', backPage: this.state.backPage})
                                }else {
                                    navigation.replace('CarStockListPage');
                                }
                            }
                        }
                    }, 1000);
                } else {
                    ToastToUser(result.msg ? result.msg : result.statusText)
                }
            })
            .catch((error) => {
                if (this.Loading) {
                    this.Loading.hide();
                }
            });
    }

    formatBrand(result) {
        this.setState({
            speciesName: result.seriesName + '·' + result.speciesName,
            brand: result.brandId,
            series: result.seriesId,
            species: result.speciesId,
            carName: result.brandName + '#' + result.seriesName + '#' + result.speciesName
        })
    }

};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F9F9F9',
    },
    rightBox: {
        height: '100%',
        width: 70,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'flex-end',
    },
    rightText: {
        fontSize: 16,
        color: '#333333',
        fontWeight: 'bold',
    },
    basicInfoContainer: {
        marginTop: 10,
        width: '100%',
        flexDirection: 'column',
        paddingHorizontal: 15,
        paddingTop: 14,
        backgroundColor: '#fff'
    },
    baseText: {
        fontSize: 15,
        fontWeight: '500',
        color: '#222222',
        marginBottom: 11,
    },
    baseText1: {
        fontSize: 14,
        fontWeight: '500',
        color: '#333',
        marginBottom: 13,
    },
    alertText: {
        marginLeft: 10,
        fontSize: 15,
        color: '#FB3D3C',
    },
    expandBox: {
        paddingLeft: 16,
        paddingRight: 5,
        flexDirection: 'row',
        alignItems: 'center',
    },
    expandText: {
        color: '#666',
        fontSize: 14,
    },
    expandImg: {
        marginLeft: 3,
        width: 16,
        height: 16
    },
    descBg: {
        width: '100%',
        height: 101,
        paddingHorizontal: 10,
        paddingTop: 4,
        paddingBottom: 17,
        backgroundColor: '#F9F9F9',
        borderRadius: 6
    },
    textInput: {
        color: '#333333',
        fontSize: 14,
        flex: 1,
        textAlignVertical: 'top',
        lineHeight: 18,
    },
    lengthText: {
        position: 'absolute',
        bottom: 5,
        right: 8,
        color: '#999999',
        fontSize: 12
    },
    bottomBox: {
        backgroundColor: '#fff',
        width: '100%',
        height: 80,
        paddingHorizontal: 15,
        justifyContent: 'center',
        alignItems: 'center'
    },
    saveBox: {
        width: '100%',
        height: 46,
        borderRadius: 23,
        backgroundColor: '#FFE000',
        justifyContent: 'center',
        alignItems: 'center'
    },
    saveText: {
        fontSize: 16,
        color: '#333'
    }
})